//
// Created by feng on 2020/6/29.
//

#include "com_kxf_hellojni_nativejni_SayHello.h"
#include "des/des.h"

/*
 * Class:     com_kxf_hellojni_nativejni_SayHello
 * Method:    getHello
 * Signature: ()Ljava/lang/String;
 */
extern "C" JNIEXPORT jstring JNICALL Java_com_kxf_hellojni_nativejni_SayHello_getHello
        (JNIEnv *env, jclass jc) {
    return env->NewStringUTF("Hello From JNI!");
}

/*
 * Class:     com_kxf_hellojni_nativejni_SayHello
 * Method:    encrypt
 * Signature: (Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;
 */
extern "C" JNIEXPORT jstring JNICALL Java_com_kxf_hellojni_nativejni_SayHello_encrypt
        (JNIEnv *env, jclass jc, jstring txt, jstring key){
    auto my3Des=new Des(env->GetStringUTFChars(key, NULL));
    std::string re = my3Des->desEncrypt(env->GetStringUTFChars(txt, NULL));
    return env->NewStringUTF(re.c_str());
}

/*
 * Class:     com_kxf_hellojni_nativejni_SayHello
 * Method:    decrypt
 * Signature: (Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;
 */
extern "C" JNIEXPORT jstring JNICALL Java_com_kxf_hellojni_nativejni_SayHello_decrypt
        (JNIEnv *env, jclass js, jstring txt, jstring key){
    auto my3Des=new Des(env->GetStringUTFChars(key, NULL));
    std::string re = my3Des->desDecrypt(env->GetStringUTFChars(txt, NULL));
    return env->NewStringUTF(re.c_str());
}

